import pygame, math, random
from Controls import *
from Constants import *
import Game
# import Spawn, Particle
#import Stuff


'''

notes/bugs/to-do


'''



class GameEscape(Game.Game):
	'''The game object.'''
	def __init__(self, size, loc, sound):
		'''Initializes the game.'''
		Game.Game.__init__(self, size, loc, sound)

		#gameplay variables
		self.score = 0

		#game objects
		self.world = None
		self.newobject = None
		self.player = None

		#object lists
		self.stuffs = []
		# self.spawns = []
		# self.bg_spawns = []
		# self.fg_spawns = []

		#hud
		#self.hud = Hud.Hud()

	def newlevel(self, leveldata=""):
		'''Interprets a loaded level file's data into a new level. Prepares objects for a new level.'''
		#reset game states
		self.leveldata = leveldata
		self.active = True
		self.endgame = False
		self.wingame = False
		self.pause = False
		self.reset = False

		self.world = None#World.World()
		self.stuffs = []

		#parse and interpret data
		data = [o.split(',') for o in leveldata.split(';')]
		for part in data:
			pass
			# if part[0] == "spawn":
				# self.spawns.append(Spawn.Spawn((int(part[1]), int(part[2])), Particle.Particle, **dict([tuple(p.split('=')) for p in part[4].split('|')])))


		#test stuff directly

		# self.spawns.append(Spawn.Spawn((320,240), Particle.Particle))

		# self.stuffs.append(Stuff.Stuff())

	def resetlevel(self):
		'''Resets the current level without reloading it.'''
		#save check before?
		self.setpause(False)
		self.newlevel(self.leveldata)

	def update(self, delta):
		'''Updates all game objects.'''
		# if self.reset:
			# return

		#interpret game-specific events
		# if new_events["lmb"]:
			# pass

		#game update
		

		#object update
		# for s in self.stuffs:
			# s.update()

		# for s in self.spawns:
			# s.update()

		#check game status
		# if win condition:
			# self.wingame = True
			# self.reset = True
			# self.active = False
		# elif lose condition:
			# self.reset = True
			# self.active = False

		#calculate camera displacement (for scrolling screens)
		# self.camdisp = (0,0)

		#post-update reset values
		pass

		#debug print everything
		#print len(self.stuffs)
		# p = 0
		# for s in self.spawns:
			# p += len(s.particles)
		# print p

	def draw(self, surf):
		'''Draws all game objects.'''
		self.camsurf.blit(black, self.camdisp)

		# for s in self.stuffs:
			# s.draw(self.camsurf, self.camdisp)

		surf.blit(self.camsurf, self.loc)
